// 导入用户集合
const { CollectionCategory } = require('../../../model/collectionCategory');
// 引入分页模块
const pagination = require('mongoose-sex-page')

module.exports = async (req, res) => {
  let categories = []
  if (!req.query.pageIndex) {
      // 全部
      categories = await CollectionCategory.find().sort({_id: -1})
  } else {
      const { pageIndex, pageSize } = req.query
      // 分页
      categories = await pagination(CollectionCategory).find().sort({_id: -1}).page(pageIndex).size(pageSize).exec()
  }
  res.json({
      data: categories
  })
}